import { IPSEditor } from '../ipseditor';
import { IPSSysPanelField } from './ipssys-panel-field';
import { PSSysPanelItemImpl } from './pssys-panel-item-impl';
import { IPSSysCss } from '../../res/ipssys-css';
import { IPSSysImage } from '../../res/ipssys-image';

export class PSSysPanelFieldImpl extends PSSysPanelItemImpl implements IPSSysPanelField {
  get fieldStates(): 1 | 2 {
    return this.M.fieldStates != null ? this.M.fieldStates : 0;
  }

  get labelCssStyle(): string {
    return this.M.labelCssStyle;
  }

  get labelDynaClass(): string {
    return this.M.labelDynaClass;
  }

  protected labelpssyscss: IPSSysCss | null = null;

  getLabelPSSysCss(): IPSSysCss | null {
    if (this.labelpssyscss != null) return this.labelpssyscss;
    const value = this.M.getLabelPSSysCss;
    if (value == null) {
      return null;
    }
    this.labelpssyscss = this.getPSModel4('res.IPSSysCss', value, 'getLabelPSSysCss') as IPSSysCss;
    return this.labelpssyscss;
  }

  get labelPSSysCss(): IPSSysCss | null {
    return this.getLabelPSSysCss();
  }

  getLabelPSSysCssMust(): IPSSysCss {
    const value = this.getLabelPSSysCss();
    if (value == null) {
      throw new Error('未指定标签样式表对象');
    }
    return value;
  }

  get outputCodeListConfigMode(): 0 | 1 | 2 {
    return this.M.outputCodeListConfigMode != null ? this.M.outputCodeListConfigMode : 0;
  }

  protected pseditor: IPSEditor | null = null;

  getPSEditor(): IPSEditor | null {
    if (this.pseditor != null) return this.pseditor;
    const value = this.M.getPSEditor;
    if (value == null) {
      return null;
    }
    this.pseditor = this.getPSModel4('control.IPSEditor', value, 'getPSEditor') as IPSEditor;
    return this.pseditor;
  }

  get psEditor(): IPSEditor | null {
    return this.getPSEditor();
  }

  getPSEditorMust(): IPSEditor {
    const value = this.getPSEditor();
    if (value == null) {
      throw new Error('未指定编辑器对象');
    }
    return value;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定属性项图片对象');
    }
    return value;
  }

  get valueFormat(): string {
    return this.M.valueFormat;
  }

  get valueItemName(): string {
    return this.M.valueItemName;
  }

  get viewFieldName(): string {
    return this.M.viewFieldName;
  }

  get allowEmpty(): boolean {
    return this.M.allowEmpty != null ? this.M.allowEmpty : true;
  }

  get convertToCodeItemText(): boolean {
    return this.M.convertToCodeItemText != null ? this.M.convertToCodeItemText : false;
  }

  get hidden(): boolean {
    return this.M.hidden;
  }

  get needCodeListConfig(): boolean {
    return this.M.needCodeListConfig != null ? this.M.needCodeListConfig : false;
  }

  get showCaption(): boolean {
    return this.M.showCaption;
  }

  get cls(): string {
    return 'PSSysPanelFieldImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.panel.IPSPanelField' || cls == 'control.panel.IPSSysPanelField') return true;
    return super.instanceof(cls);
  }
}
